package pkg.genericity.utils;

import java.io.IOException;
import java.util.List;
import java.util.ResourceBundle;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import pkg.genericity.DAO.BeanDAO;

public class GenericFilter implements Filter {
	
	private static String dataObjectsPackage = "pkg.genericity.DO";

    public GenericFilter() {
    	super();
    	ResourceBundle bundle = ResourceBundle.getBundle("pkg.genericity.app");
    	dataObjectsPackage=bundle.getString("data.objects.package");
    }

	public void destroy() {
	}

	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
		chain.doFilter(request, response);
	}

	public void init(FilterConfig fConfig) throws ServletException {
		
		BeanUtil util = new BeanUtil();
		BeanDAO dao = new BeanDAO();
		
		List<Class<?>> list = util.getAllClasses(dataObjectsPackage);
		for (Class<?> clazz:list) {
			dao.verifyAndUpdateDB(clazz);
		}
		
	}

}
